package work.boom1;

/**
 * @author lijunhao
 * 2023/7/12 作业
 * @description TODO
 */
public class Person {
   private String name;
    private int age;
    private  boolean gender;
    private Person partner;

    public Person(String name, int age, boolean gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public void marry(Person p) {
        if (partner != null) {
            System.out.println(name + "已经结婚了。");
        } else if (p.getPartner() != null) {
            System.out.println(p.getName() + "已经结婚了。");
        } else if (gender == p.gender) {
            System.out.println("同性不能结婚。");
        } else if (( gender&&age < 24) || ( !gender&&age < 22)) {
            System.out.println("年龄未达到结婚要求。");
        } else {
            partner = p;
            p.setPartner(this);
            System.out.println(name + "和" + p.getName() + "结婚了，祝福他们！");
        }
    }

    public Person getPartner() {
        return partner;
    }

    public void setPartner(Person partner) {
        this.partner = partner;
    }

    public String getName() {
        return name;
    }


}

